//
//  Global.m
//  Ghac 4S
//
//  Created by apple on 11-8-23.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "Global.h"
void KLog(NSString* target, ...)
{
//    va_list arg_ptr;
//    va_start(arg_ptr, target);
//    NSString* tmpTarget;
//    while(YES)
//    {
//        tmpTarget = va_arg(arg_ptr, NSString*);
//        if (tmpTarget)
//        {
//            NSLog(@"%@", tmpTarget);
//        }
//        else
//        {
//            break;
//        }
//    }
//    va_end(arg_ptr);
}


@implementation Global
@synthesize updateTimeDelta;
- (id)init
{
    self = [super init];
    if (self)
    {
        // Initialization code here.
        m_carNameList = [[NSArray alloc] initWithObjects:@"08雅阁", @"05奥德赛", @"新飞度", @"锋范", @"新奥德赛",  @"歌诗图", @"理念S1", nil];
        NSDictionary* dic = [[Global globalConfigDic] valueForKey:@"CarInfo"];
        m_carNameList = [[Global globalConfigDic] valueForKey:@"CarInfo"];
    }
    return self;
}

-(void)dealloc
{
    KRELEASE(m_carNameList);
    [super dealloc];
}
+(Global *)mainInstance
{
    if (g_mainGlobal == nil)
    {
        g_mainGlobal = [[Global alloc] init];
    }
    
    return g_mainGlobal;
}
+(NSDictionary *)globalConfigDic
{
    if (g_config == nil)
    {
        g_config = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"]];
    }
    return g_config;
}
+(id<MainViewSwitchAction>)mainRootController
{
    return (id<MainViewSwitchAction>)[([[UIApplication sharedApplication].windows objectAtIndex:0]) rootViewController];
}
+(NSString *)BTN_L_NEWS
{
    return @"news";
}
+(NSString *)BTN_L_CONTACT
{
    return @"contact";
}
+(NSString *)BTN_L_LOCATION
{
    return @"location";
}
+(NSString *)BTN_L_PRICE
{
    return @"parts price";
}
+(NSString *)BTN_L_REPAIR
{
    return @"parts repair";
}
+(NSString *)BTN_L_QA
{
    return @"q&a";
}
+(NSString *)SHOP_DETAIL_VIEW
{
    return @"shopDetail";
}

+(NSArray *)cartypeList
{
    return [[[Global globalConfigDic] valueForKey:@"CarInfo"] allKeys];
}
+(NSArray *)carInfoList
{
    return [[[Global globalConfigDic] valueForKey:@"CarInfo"] allValues];
}

+(void)phoneCall:(NSString *)telNum
{
    NSString* str;
    if ([telNum rangeOfString:@"tel:"].length == 0)
    {
        str = [[NSString alloc] initWithFormat:@"tel:%@", telNum];
    }
    else
    {
        str = [telNum copy];
    }
    NSURL* url = [[NSURL alloc] initWithString:str];
    [str release];
    
    NSLog(@"call %@", url);
    [[UIApplication sharedApplication] openURL:url];
    [url release];
}

@end
